<template>
  <div class="error-page-main">
    <img class="error-page-main__tip-img" :src="tipImg" alt="错误提示">
    <span class="error-page-main__code js-code" v-text="errCode" />
    <p class="error-page-main__message js-message" v-text="errMsg" />
    <button icon="arrow-left" class="error-page-main__primary-btn js-primary-btn" @click="back">
      返回
    </button>
  </div>
</template>

<script>
import tipImg from '@/assets/400_images/tip-img.png'

const DEF_ERR_CODE = '400'
const DEF_ERR_MSG = '抱歉，出错了，请联系管理员！'

export default {
  name: 'Page400',
  data() {
    return {
      tipImg: tipImg + '?' + +new Date(),
      errCode: DEF_ERR_CODE,
      errMsg: DEF_ERR_MSG
    }
  },
  watch: {
    $route: {
      immediate: true,
      handler(route) {
        this.errCode = route.params.code || DEF_ERR_CODE
        if (this.errCode.length > 3) {
          this.errCode = this.errCode.substring(0, 3)
        }
        this.errMsg = route.params.msg || DEF_ERR_MSG
      }
    }
  },
  methods: {
    back() {
      if (this.$route.params.back) {
        this.$router.push({ path: this.$route.params.back })
      } else {
        this.$router.go(-1)
      }
    }
  }
}
</script>

<style scoped>
    .error-page-main {
        position: relative;
        padding-top: 50px;
        text-align: center;
    }
    .error-page-main__tip-img {
        max-width: 100%;
        width: 220px;
        height: 200px;
    }
    .error-page-main__code {
        position: absolute;
        top: 82px;
        left: 50%;
        width: 56px;
        margin-left: -108px;
        color: #888;
        font-size: 16px;
    }
    .error-page-main__message {
        padding: 3px 0 10px;
        font-size: 16px;
        color: #666;
    }
    .error-page-main__primary-btn {
        min-width: 120px;
        height: 40px;
        line-height: 40px;
        padding-left: 10px;
        padding-right: 10px;
        border: none;
        border-radius: 4px;
        color: #fff;
        font-size: 16px;
        background-color: #E6454A;
        cursor: pointer;
    }
    .error-page-main__primary-btn:active {
        background-color: rgba(230, 69, 74, 0.8);
    }
    .error-page-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding-top: 10px;
        padding-bottom: 10px;
        font-size: 12px;
        color: #999;
        text-align: center;
        background-color: #f5f5f5;
    }

    @media (min-width: 576px) {
        .error-page-main__tip-img {
            max-width: 100%;
            width: 275px;
            height: 250px;
        }
        .error-page-main__code {
            top: 90px;
            width: 70px;
            margin-left: -136px;
            font-size: 18px;
        }
    }
</style>
